/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {

        vector<vector<int>> ret;
        if(nullptr==root){

            return ret;
        }
        queue<TreeNode*> q;
        q.push(root);
        while(q.size()){

            int sz=q.size();
            vector<int> tmp;
            while(sz--){

                TreeNode* u=q.front();
                q.pop();
                tmp.push_back(u->val);
                if(u->left){

                    q.push(u->left);
                }
                if(u->right){

                    q.push(u->right);
                }
            }
            ret.push_back(tmp);
        }
        return ret;
    }
};
